home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD32 Gamer 13 / CD32 Gamer - 1995 - Issue 13.iso / demos / agatunnel / agatunnel.c < prev    next >
C/C++ Source or Header  |  1994-01-08  |  4KB  |  183 lines

  1. #include <exec/types.h>
  2.  
  3. #include <intuition/intuition.h>
  4. #include <intuition/screens.h>
  5. #include <utility/tagitem.h>
  6.  
  7. #include <proto/exec.h>
  8. #include <proto/intuition.h>
  9. #include <proto/graphics.h>
  10. #include <proto/dos.h>
  11.  
  12. #include <string.h>
  13. #include <stdlib.h>
  14.  
  15. #define TBITPLANES    (6)
  16. #define TCOLORS        (1<<TBITPLANES)
  17.  
  18. static long __oslibversion = 39;
  19.  
  20. static void errorexit(void);
  21. static void cyclecolorspec(ULONG *, WORD, UWORD, UWORD, UWORD);
  22. static void bouncecolor(UWORD *, WORD *);
  23.  
  24. void main(int argc, char ** argv)
  25. {
  26.     struct Screen    * screen;
  27.     struct Window    * window;
  28.  
  29.     static ULONG            colorspec[1+TCOLORS*3+1];    // Guaranteed to be zero?
  30.     static WORD                areabuffer[10];
  31.     static struct AreaInfo    areainfo;
  32.     static struct TmpRas    tmpras;
  33.     PLANEPTR                raster;
  34.  
  35.     WORD        i;
  36.     WORD        xstep,
  37.                 ystep;
  38.  
  39.     screen = OpenScreenTags(NULL,
  40. //        SA_DisplayID,    PAL_MONITOR_ID|HIRESLACE_KEY,
  41. //        SA_Width,        640, //1280,
  42. //        SA_Height,        256, //400,
  43.         SA_Depth,        TBITPLANES,
  44.         SA_Title,        "AGATunnel",
  45.         SA_Type,        CUSTOMSCREEN,
  46. //        SA_AutoScroll,    FALSE,
  47. //        SA_Pens,        &penspec,
  48. //        SA_SysFont,        0,
  49. //        SA_Overscan,    OSCAN_TEXT,
  50. //        SA_,    ,
  51. //        SA_,    ,
  52.         SA_LikeWorkbench, TRUE,
  53. //        SA_ShowTitle, FALSE,
  54.         TAG_END);
  55.  
  56.     if(screen == NULL)
  57.         errorexit();
  58.  
  59.     window = OpenWindowTags(NULL,
  60.         WA_Left, 0,
  61.         WA_Top, 0,
  62.         WA_Width, screen->Width,
  63.         WA_Height, screen->Height,
  64.         WA_Title, NULL,
  65.         WA_CustomScreen, screen,
  66.         WA_Borderless, FALSE,
  67.         WA_DragBar, FALSE,
  68.         WA_Activate, TRUE,
  69.         WA_SmartRefresh, TRUE,
  70.         WA_Backdrop, FALSE,
  71.         WA_NoCareRefresh, TRUE,
  72. //        WA_,,
  73. //        WA_,,
  74. //        WA_,,
  75. //        WA_,,
  76.         TAG_END);
  77.  
  78.     if(window==NULL)
  79.     {    CloseScreen(screen);
  80.         errorexit();
  81.     }
  82.  
  83.     InitArea(&areainfo, areabuffer, 10*2/5);
  84.     window->RPort->AreaInfo = &areainfo;
  85.  
  86.     raster = AllocRaster(window->Width*2, window->Height*2);
  87.     InitTmpRas(&tmpras, raster, RASSIZE(window->Width*2, window->Height*2));
  88.     window->RPort->TmpRas = &tmpras;
  89.  
  90. /*
  91.  ****************************************************
  92.  */
  93.     xstep = (window->Width-50)/2/TCOLORS;
  94.     ystep = (window->Height-50)/2/TCOLORS;
  95.     for(i=TCOLORS-1; i>0; i--)
  96.     {    SetAPen(window->RPort, (ULONG)(TCOLORS - i));
  97. /*        AreaEllipse(window->RPort, window->Width/2 , window->Height/2,
  98.                     ((window->Width-20)*i)/2/TCOLORS,
  99.                     ((window->Height-20)*i)/2/TCOLORS);
  100. */
  101.         AreaEllipse(window->RPort, window->Width/2 , window->Height/2,
  102.                     (((window->Width*4)/3)*i)/2/TCOLORS,
  103.                     (((window->Height*4)/3)*i)/2/TCOLORS);
  104.  
  105.         AreaEnd(window->RPort);
  106.     }
  107.  
  108.     {
  109.         UWORD    red,
  110.                 green,
  111.                 blue;
  112.         WORD    rspeed,
  113.                 gspeed,
  114.                 bspeed;
  115.  
  116.         colorspec[0] = TCOLORS<<16 | 0;
  117.         srand(141);
  118.         red = green = blue = 0;
  119.         rspeed = 950; //((UWORD)rand())&0x00ff - 128;
  120.         gspeed = 901; //((UWORD)rand())&0x00ff - 128;
  121.         bspeed = 863; //((UWORD)rand())&0x00ff - 128;
  122.  
  123.         while(TRUE)
  124.         {    cyclecolorspec(&colorspec[1], TCOLORS, red, green, blue);
  125.             WaitTOF();
  126.             LoadRGB32(&screen->ViewPort, colorspec);
  127.  
  128.             bouncecolor(&red, &rspeed);
  129.             bouncecolor(&green, &gspeed);
  130.             bouncecolor(&blue, &bspeed);
  131.  
  132.             if((SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) != 0)
  133.                 break;
  134.             // Delay(1);
  135.         }
  136.     }
  137.  
  138.     FreeRaster(raster, window->Width, window->Height);
  139.     CloseWindow(window);
  140.     CloseScreen(screen);
  141.     exit(0);
  142. }
  143.  
  144. static void errorexit(void)
  145. {
  146.     static char message[] = "Some fatal error - panic!\n";
  147.  
  148.     Write(Output(), message, sizeof(message));
  149.     exit(20);
  150. }
  151.  
  152. static void cyclecolorspec(ULONG * table, WORD tablesize, UWORD r, UWORD g, UWORD b)
  153. {
  154.     WORD    i;
  155.  
  156.     for(i=0; i<tablesize-1; i++)
  157.     {    table[i*3] = table[(i+1)*3];
  158.         table[i*3+1] = table[(i+1)*3+1];
  159.         table[i*3+2] = table[(i+1)*3+2];
  160.     }
  161.  
  162.     table[(tablesize-1)*3] = r<<16;
  163.     table[(tablesize-1)*3 + 1] = g<<16;
  164.     table[(tablesize-1)*3 + 2] = b<<16;
  165. }
  166.  
  167. static void bouncecolor(UWORD * col, WORD * speed)
  168. {
  169.     LONG    tmp;
  170.  
  171.     tmp = (*col)+(*speed);
  172.     if(tmp > 65000)
  173.     {    tmp = 65000;
  174.         (*speed) = -(*speed);
  175.     }
  176.     if(tmp<0)
  177.     {    tmp = 0;
  178.         (*speed) = -(*speed);
  179.     }
  180.  
  181.     (*col) = (UWORD)tmp;
  182. }
  183.